#include <windows.h>
#include <stdio.h>
//out 
#include "GetPSINIBinary.h"



static	CHAR g_tmp_GetPrivate_szReadStrBuffer[65536] = {0};

DWORD 
WINAPI 
GetPrivateProfileBinary
(
IN LPCTSTR	lpsziniSection,		// section name
IN LPCTSTR	lpsziniKey,		// key name
IN LPVOID	lpBinBuff,		// return buffer
IN size_t	uSizeBinBuff,		// size of return buffer
IN LPCTSTR	szINIFile		// INI File
)
	{
	DWORD	RetVal = 0 ;

	DWORD	strLen = 0 ;

	DWORD	dwSSCAN_VAL = 0;

	
	strLen = RetVal = GetPrivateProfileString(lpsziniSection,lpsziniKey,"ReadError",g_tmp_GetPrivate_szReadStrBuffer,
		sizeof(g_tmp_GetPrivate_szReadStrBuffer),szINIFile ) ;

	if (lstrcmp(g_tmp_GetPrivate_szReadStrBuffer,"ReadError") == 0 )
		{
		return 0 ;
		}

	if ( strLen > sizeof(g_tmp_GetPrivate_szReadStrBuffer) )
		{
		return sizeof(g_tmp_GetPrivate_szReadStrBuffer)+1;
		}

	//CHAR => Hex 
	UINT i ;
	for (i=0;(i < strLen/2) && (i < uSizeBinBuff) ;i++ )
	{	
		dwSSCAN_VAL = 0 ;

		if ( 1 == sscanf(&g_tmp_GetPrivate_szReadStrBuffer[i*2],"%02x",&dwSSCAN_VAL) )
		{
			*((LPBYTE)lpBinBuff+i) = LOBYTE(dwSSCAN_VAL);
		}
		else
		{	break;

		}

	}

	

	return i;
	}